
var Comment = require('../models/comment.js')



exports.saveComment = function(req,res){


	var _comment = req.body.comment

	

	var comment = new Comment(_comment)

	comment.save(function(err,comment){

		if(err){
			console.log(err)

		}else{
			
			res.redirect('/topic/'+comment.post)
		}
	})
	
}


exports.updateComment = function(req,res){

	var thumbsCount = req.body.thumbsCount

	var commentId = req.body.commentId

	Comment.getById(commentId,function(err,comment){

		if(err){

			console.log(err)
		}

		comment.thumbsUpCount = thumbsCount

		comment.save(function(err,comment){

			if(err){

				console.log(err)
			}

			res.json({'thumbsCount':comment.thumbsUpCount})
		})
	})
}